LLVM_CONFIG=/home/zzy/llvm-16.0.6/bin/bin/llvm-config
CXX=/home/zzy/llvm-16.0.6/bin/bin/clang++

# LLVM_CONFIG=llvm-config
# CXX=clang++

CXXFLAGS+=$(shell $(LLVM_CONFIG) --cxxflags) -fno-rtti
CPPFLAGS+=$(shell $(LLVM_CONFIG) --cppflags) -g
LDFLAGS+=$(shell $(LLVM_CONFIG) --ldflags)

CLANGLIBS= \
  -Wl,--start-group \
  -lclang \
  -lclangFrontend \
  -lclangDriver \
  -lclangSerialization \
  -lclangParse \
  -lclangSema \
  -lclangAnalysis \
  -lclangEdit \
  -lclangAST \
  -lclangLex \
  -lclangBasic \
  -lclangTooling \
  -lclangSupport \
  -lclangASTMatchers \
  -Wl,--end-group

SRC=$(wildcard *.cpp)
OBJ=$(patsubst %.cpp, %, $(SRC))

.PHONY:all clean
all: $(OBJ)

%:%.cpp
	@echo Compiling $*.cpp
	$(CXX) $< $(CPPFLAGS) $(CXXFLAGS) -o $@ $(LDFLAGS) $(CLANGLIBS) `$(LLVM_CONFIG) --libs --system-libs`

run:
	./find-class-decls "namespace n { namespace m { class C {}; } }"

clean:
	rm -rf $(OBJ)
